﻿using System.IO;

namespace MyBasicLib.IO
{
    public static class PathHelper
    {
        static string currentDirectory;
        public static void EnsureDirectoryExists(string fileName)
        {
            Check.Argument.IsNotEmpty(fileName, "fileName");
            var path = string.IsNullOrEmpty(Path.GetExtension(fileName)) ? fileName : Path.GetDirectoryName(fileName);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        } 
        /// <summary>
        /// 当前目录,如果是网站是网站根目录,如果是桌面程序则是程序所在目录.
        /// </summary> 
        public static string CurrentDirectory
        {
            get
            {
                return currentDirectory ?? (currentDirectory = System.AppDomain.CurrentDomain.BaseDirectory);
            }
        }
    }
}